package com.things8.iot.baseIot.controller;

import com.alibaba.fastjson.JSON;
import com.things8.iot.baseIot.configeration.Userconfiguration;
import com.things8.iot.baseIot.dto.QueryDeviceDto;
import com.things8.iot.baseIot.service.SysDeviceService;
import com.things8.iot.common.result.GlobalResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.Min;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/5/2 21:14
 */
@RestController
@RequestMapping("device")
@Validated
public class DeviceController {

    private static final Logger log = LoggerFactory.getLogger(DeviceController.class);

    @Resource
    private SysDeviceService sysDeviceService;

    @Resource
    private Userconfiguration userconfigeration;

    @GetMapping("queryBySysId/{sysId}")
    public GlobalResult queryBySysId(@Min (value = 99,message = "sysId最小值为99") @PathVariable("sysId") Long sysId) {
        return GlobalResult.success(sysDeviceService.queryBySysId(sysId));
    }

    @PostMapping("pageList")
    public GlobalResult pageList(@Valid @RequestBody QueryDeviceDto  queryDeviceDto) {
        log.info("userconfigeration :{}", JSON.toJSONString(userconfigeration));

        return GlobalResult.success(sysDeviceService.pageList(queryDeviceDto));
    }

    @PostMapping("async")
    public void async() {
        for (int i = 0; i < 200; i++) {
            sysDeviceService.async();
        }
    }

}
